package com.simple.component;

import android.util.Log;

import com.billy.cc.core.component.CC;
import com.billy.cc.core.component.CCResult;
import com.billy.cc.core.component.Chain;
import com.billy.cc.core.component.ICCInterceptor;
import com.billy.cc.core.component.IComponentCallback;
import com.billy.cc.core.component.IGlobalCCInterceptor;

import java.util.Map;

/**
 * Copyright (C), 2016-2020,呼我出行网络科技有限公司
 * FileName: LoginCcInterceptor
 * Author: Administrator
 * Date: 2020/11/4 10:30
 * Description:登录拦截器
 * History:
 */
public class LoginCcInterceptor implements ICCInterceptor {
    private String callId;

    @Override
    public CCResult intercept(Chain chain) {
//        CcCall.callComponentAsyncMain(ComponentAction.ACTION_LOGIN,
//                ComponentAction.ACTION_LOGIN, false, new IComponentCallback() {
//                    @Override
//                    public void onResult(CC cc, CCResult result) {
//                        Log.e("tgl===", "cc result : " + result.toString());
//                        if (result.isSuccess()) {
//                            Log.e("tgl===", "已登录");
//                            CCResult ccResult = chain.proceed();
//                            chain.getCC().call();
//                        }
//
//                    }
//                });
//        CCResult ccResult = chain.proceed();
//        Map mapTest = ccResult.getDataMap();
//        mapTest.put(Global.EXTRA_TEST, "拦截测试");
//        ccResult.setDataMap(mapTest);

        CCResult result = CcCall.callComponent(ComponentAction.ACTION_LOGIN, ComponentAction.ACTION_LOGIN);
        Log.e("tgl===", "cc result : " + result.toString());
        if (result.isSuccess()) {
            CCResult ccResult = chain.proceed();
            Log.e("tgl===", "ccResultcc : " + ccResult.toString());
            Map map = ccResult.getDataMap();
            map.put(Global.KEY_USERNAME, result.getDataItem(Global.KEY_USERNAME));
            ccResult.setDataMap(map);
        }
        return null;
    }

}
